package com.example.teaching_server.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;

/**
 * 创建子主题请求DTO
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "创建子主题请求参数")
public class CreateSubThemeRequest {

    @NotNull(message = "父主题ID不能为空")
    @Positive(message = "父主题ID必须是正整数")
    @Schema(description = "父主题ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
    private Long parentId;

    @NotBlank(message = "子主题名称不能为空")
    @Size(min = 1, max = 100, message = "子主题名称长度在1-100字符之间")
    @Schema(description = "子主题名称", example = "人工智能基础", requiredMode = Schema.RequiredMode.REQUIRED)
    private String name;

    @NotBlank(message = "子主题标签不能为空")
    @Size(min = 1, max = 50, message = "子主题标签长度在1-50字符之间")
    @Schema(description = "子主题标签", example = "AI基础", requiredMode = Schema.RequiredMode.REQUIRED)
    private String label;

    @Size(max = 500, message = "描述长度不能超过500字符")
    @Schema(description = "子主题描述", example = "人工智能基础知识入门")
    private String description;

    @Size(max = 500, message = "封面图片URL长度不能超过500字符")
    @Schema(description = "封面图片URL", example = "/images/ai-basic.jpg")
    private String coverImage;

    @PositiveOrZero(message = "排序顺序不能为负数")
    @Schema(description = "排序顺序", example = "1")
    @Builder.Default
    private Integer sortOrder = 0;

    /**
     * 验证父主题ID有效性
     */
    public boolean isValidParentId() {
        return parentId != null && parentId > 0;
    }

    /**
     * 获取主题标识符（名称+标签）
     */
    @Schema(description = "主题标识符", accessMode = Schema.AccessMode.READ_ONLY)
    public String getThemeIdentifier() {
        return name + " (" + label + ")";
    }
}
